﻿/*
Copyright © 2011 François Karman

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

See <license.txt> for the complete license of the software.
*/

using NUnit.Framework.Api;

namespace NUnit.Phone.Gui
{
    /// <summary>
    /// The main view model instance.
    /// </summary>
    public class MainViewModel : AbstractViewModel
    {
        /// <summary>
        /// A value indicating whether the result should be displayed
        /// instead of the test list.
        /// </summary>
        private bool displayResult;

        /// <summary>
        /// The current displayed test.
        /// </summary>
        private ITest currentTest;

        /// <summary>
        /// The view model associated with the test results.
        /// </summary>
        private ResultListViewModel result;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        /// <param name="testIdentifier">
        /// The identifier of the displayed test.
        /// </param>
        /// <param name="displayResult">
        /// A value indicating whether the result should be displayed
        /// instead of the test list.
        /// </param>
        public MainViewModel(int testIdentifier, bool displayResult)
        {
            this.DisplayResult = displayResult;
            this.CurrentTest = TestManager.Instance.RetrieveTest(testIdentifier);
            this.Result = ResultListViewModel.Instance;
        }

        /// <summary>
        /// Gets or sets a value indicating whether the result should be displayed
        /// instead of the test list.
        /// </summary>
        public bool DisplayResult
        {
            get { return this.displayResult; }
            set
            {
                if (this.displayResult != value)
                {
                    this.displayResult = value;
                    this.RaisePropertyChanged("DisplayResult");
                }
            }
        }

        /// <summary>
        /// Gets the current displayed test.
        /// </summary>
        public ITest CurrentTest
        {
            get { return this.currentTest; }
            set
            {
                if (this.currentTest != value)
                {
                    this.currentTest = value;
                    this.RaisePropertyChanged("CurrentTest");
                }
            }
        }

        /// <summary>
        /// Gets the view model associated with the test results.
        /// </summary>
        public ResultListViewModel Result
        {
            get { return this.result; }
            set
            {
                if (this.result != value)
                {
                    this.result = value;
                    this.RaisePropertyChanged("Result");
                }
            }
        }
    }
}
